import { connect } from 'dva'
import { routerRedux } from 'dva/router'

// 权限组件
function ProviderRouter({ children, loginId, onNotLogin }) {
    if (loginId) {
        return children
    }
    // 未登录 
    onNotLogin()
    return null
}

export default connect(
    state => ({ loginId: state.loginUser }),
    dispatch => ({
        onNotLogin() {
            dispatch({ type: 'loginUser/logout' })
            dispatch(routerRedux.push('/login'))
        }
    }))(ProviderRouter)